Skip to content

Raise when a run stops before its STOP time - #8

Merged
apetros merged 2 commits into
masterfrom
fix/raise-on-divergence
Nov 20, 2026
Merged

apetros merged 2 commits into
masterfrom
fix/raise-on-divergence

Conversation

@apetros

@apetros apetros commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Problem

execSim(case) returned normally when RAMSES stopped on Divergence. Simulation stopped. The reduced GB network in stepss-test-systems diverged at t = 0.35 s on RAMSES 3.81 to 3.84 and its notebook reported it as running for three months, because the trajectory just ended at 0.34 s.

Cause (engine side)

The engine's return flag does not tell divergence apart from a finished run. In stepss-ramses, both divergence branches (src/core/simul_integr.f90:1040 and src/core/simul_decomp.f90:1727) only set end_simul=.true. and write the message to the log unit. diagno stays 0, so ramses() returns 0, the same as a run that reached STOP. The message never reaches lasterrormsglog, so getLastErr() cannot report it either. Reproduced on the bundled 3.84 library: execSim returned 0 with getSimTime() == 0.001 against a STOP at 3.0 s.

Change (wrapper side)

  • execSim() and contSim(): when the engine returns 0 (not 112), compare getSimTime() with the STOP time of the case's .dst and raise RAMSESError if the run fell short. The message quotes the engine's last t = ... line from the part of the trace file this call wrote (the engine opens its log on that file in append mode):
    RAMSES: Function execSim() returned without an error flag, but the simulation stopped at t = 0.0010 s, before the STOP time 3.0000 s. The engine reported: t = 0.0010 Divergence. Simulation stopped
  • No check on endSim() (ending early is what it does), and none for $LATENCY early stopping, which the engine logs as All equipment is latent.
  • addDisturb(t, '... STOP') at an earlier time moves the STOP time checked against.
  • New stepss.cases._dstStopTime() reads the first STOP using the same rules as _dstProblem.
  • CLAUDE.md: one bullet under Testing.

Tests

tests/test_divergence.py, each engine run in its own subprocess:

  • the Nordic case with an unreachable $NEWTON_TOLER diverges at t = 0.001 s and now raises, naming Divergence and the STOP time (failed before the fix)
  • the same case with the fault cleared reaches STOP and returns 0
  • a run paused at 1 s and ended with endSim() does not raise
  • four unit tests for _dstStopTime

Locally (macOS arm64, Python 3.14): 256 passed, 1 failed. The failure is test_ssa_archive.py::test_tar_round_trip_without_the_extraction_filter, a NameError inside Python 3.14's tarfile. It fails the same way on unmodified master, so it is not caused by this change.

Engine change

Done in SPS-L/stepss-ramses#26: divergence now returns -1 with the message in getLastErr(), which the existing non-zero-flag path raises on. The second commit here makes the engine test accept either route and adds six fake-engine tests that pin the STOP-time check on its own. The check stays, for engines up to 3.84 and for early ends the engine still does not flag (a model stop inside the Newton evaluation under $SCHEME DE is still suspected to return 0, see SPS-L/stepss-ramses#26).

Verified against both the bundled 3.84 library and a ramses.so built from SPS-L/stepss-ramses#26: tests/test_divergence.py passes (13 tests) and the full suite gives 262 passed, 1 failed (the Python 3.14 tarfile issue above).

RAMSES ends a run on "Divergence. Simulation stopped" by setting its
end-of-simulation flag alone, so ramses() returns 0, the same flag as a
run that reached STOP. execSim() took that 0 as success, which is how the
reduced GB network passed for three months while its trajectory ended at
0.34 s.

execSim() and contSim() now compare getSimTime() with the STOP time of
the disturbance file when the engine returns 0, and raise RAMSESError
when the run fell short, quoting the engine's last "t = ..." line from
the part of the trace file the call wrote. endSim() skips the check, as
does $LATENCY early stopping, which the engine logs as "All equipment is
latent". A STOP added through addDisturb() moves the time checked
against.

tests/test_divergence.py reaches the engine's divergence branch on the
Nordic case with an unreachable $NEWTON_TOLER, and checks that a run
reaching STOP and an endSim() before STOP still pass.
…engine

The engine now returns -1 for a diverged run, with the message in
getLastErr(), which the non-zero-flag path already raises on. The engine
test accepts either that or the STOP-time check, so it passes against
the bundled 3.84 library and a newer one alike.

Six fake-engine tests pin the STOP-time check on its own, whatever
library is bundled: an unflagged early end raises and quotes the
engine's line from this call's part of the trace only; reaching STOP,
a latency early stop and a pause pass; a STOP added at run time moves
the time checked against. The check stays as the backstop for older
engines and for early ends the engine still does not flag.
@apetros
apetros merged commit 13fd6be into master Nov 20, 2026
6 checks passed
@apetros
apetros deleted the fix/raise-on-divergence branch November 20, 2026 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant